<?php

namespace IDock\Insurance\DBIC\Request;

use IDock\Insurance\DBIC\DBICEnums;
use IDock\Insurance\DBIC\Response\SpecialClausesResponse;
use IDock\Visitor\Premium\PremiumCoverageVisitor;
use IDock\Visitor\Premium\PremiumInquiryVisitor;

class SpecialClausesRequest extends AllDBICRequest
{
    protected $route = 'dbic/bds/bdengage/getBDEngage';

    protected $response = SpecialClausesResponse::class;

    protected $urlTip = '特约初始化接口';

    private $riskCode = '';

    private $kindList = [];

    /*** @var  $visitor PremiumInquiryVisitor */
    public $visitor;

    public function generate(): array
    {
        return [
            'insuranceId' => 'DBIC',
            'riskCode' => $this->riskCode,
            'comCode' => $this->visitor->getExtInfoVisitor()->argc['comCode'] ?? '',
            'carKindCode' => DBICEnums::$carKindCode[$this->visitor->getVehicleVisitor()->carKindCode] ?? '',
            'seatCount' => $this->visitor->getVehicleVisitor()->vehicleSeat,
            'useNatureCode' => DBICEnums::$causeType[$this->visitor->getVehicleVisitor()->causeType] ?? '',
            'appliName' => $this->visitor->getApplicantVisitor()->name,
            'insuredName' => $this->visitor->getInsuredVisitor()->name,
            'carOwner' => $this->visitor->getOwnerVisitor()->name,
            'kindList' => $this->kindList
        ];
    }

    public function setBi()
    {
        $this->riskCode = '0510';
        foreach ($this->visitor->getCoverageVisitorList() as $coverage) {
            /*** @var PremiumCoverageVisitor $coverage */
            $this->kindList[] = [
                'kindcode' => DBICEnums::$coverageCode[$coverage->coverageCode]
            ];
        }
    }

    public function setCi()
    {
        $this->riskCode = '0590';
    }
}